import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import commonjs from '@rollup/plugin-commonjs';
import { resolve } from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
// import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import'
export default defineConfig({
  plugins: [
    commonjs(),
    vue(),
    // createStyleImportPlugin({
    //   resolves: [
    //     VxeTableResolve()
    //   ],
    // }),
    createSvgIconsPlugin({
      // 指定要缓存的文件夹
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
      // 指定symbolId格式
      symbolId: '[name]'
    }),

  ],
  server: {
    host: '0.0.0.0', //解决“vite use `--host` to expose”
    port: 9999,
    open: true,
    proxy: {
      '/api': {
        target: 'http://192.168.44.57:8888', // 指定后端服务器的 URL
        changeOrigin: true, // 是否改变请求头的来源为目标 URL
        rewrite: (path) => path.replace(/^\/api/, ''), // 可选配置，用于重写请求路径
      },
    },
  },
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, 'src')
      }
    ],
    extensions: ['.vue', '.js', '.ts'],
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/style/variables.scss";'
      },
    }
  },
  build: {
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  }
})
